

function toLogin(phone, password) {
	if(phone != "" && password != "") {
		$.ajax({
			url: urlcore + "/api/login/loginPhoneweixin",
			type: "POST",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			data: JSON.stringify({
				phone: phone,
				password: password
			}),
			success: function(da) {
				if(da.success == true) {
					//alert(JSON.stringify(da.data.data.id));
				/*	console.log(da.data.id);
                   console.log(da.data);
                   	console.log(da.data.id);*/
					//设置cookie
					var domain_url = urlcore.split('://')[1];
					if(domain_url.indexOf(':') > -1) {
						domain_url = domain_url.split(':')[0];
					} else {
						domain_url = domain_url.split('/')[0];
					}
	document.cookie = "sid=" + da.data.data.token + ";path=/;domain=" + domain_url;
				// alert(document.cookie);
			window.location.href = "index.html";
				}else{
					alert(da.msg);
				}
			},
			error: function() {
				/* Act on the event */
				alert("error");
			}
		});
	}

}
$(function(){
	var code=getvl("code");
	if(code!="" && sessionStorage.getItem("phone")!=""){
			//sessionStorage.setItem("codess",codess);
		 $.ajax({
				url: urlcore + "/api/user/wxupdate?codess="+code,
				type: "post",
				contentType: "application/json;charset=utf-8",
				data: JSON.stringify({ //所在省市
					"password": sessionStorage.getItem("password"),
					"phone": sessionStorage.getItem("phone"),
					"code": sessionStorage.getItem("codess")
				}),
				dataType: "json",
				success: function(data) {
					//data是返回的hash,key之类的值，key是定义的文件名
					//alert(JSON.stringify(data.data));
					//	window.location.href="8.0.0zhaohuo.html";
					if(data.success == true) {
						//alert(JSON.stringify(data.data.jsonObject));
			          //toLogin(data.data.phone,data.data.password);
window.location.href = "gotoindex.html";
					} else{
					alert(data.msg);
				    }
				},
				error: function() {
					alert("修改失败");
				}
			});
	}
})



function login() {
	var phone = $("#phone").val();
	var password = $("#password").val();
	var password2 = $("#password2").val();
   
	sessionStorage.setItem("password",password);
	sessionStorage.setItem("codess",codess);
	
	//alert(uuid + "....." + code + ".." + password2 + "..." + password);
	if(!(/^1(3|4|5|7|8)\d{9}$/.test(phone))) {
		alert("手机号码有误");
		return;
	}
	if(password2 == password) {
		if(codess != "" && codess != null) {
		
          if(code!=""){
            window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx242f8ebb59f20be1&redirect_uri=http://wx.jiagangwangluo.com/wx/1.3.0zhuce.html&response_type=code&scope=snsapi_base&state=STATE&connect_redirect=1#wechat_redirect";
          }else{
          	alert("验证码未输入");
          }
		}
	} else {
		alert("密码不一致!");
		return;
	}
}
//忘记密码 
function getPassword() {
	var phone = $('#phone').val().trim();
	if(phone == '') {
		alert("请输入手机号码！");
		return false;
	}
	var code = $('#code').val().trim();
	if(code == '') {
		alert("请输入验证码！");
		return false;
	}

	var password = $('#password').val().trim();
	if(password == '') {
		alert("请输入密码！");
		return false;
	}
	var repassword = $('#repassword').val().trim();
	if(repassword == '') {
		alert("请再次输入密码！");
		return false;
	}
	if(password != repassword) {
		alert("两次输入密码不一致！");
		return false;
	}
	
	
	$.ajax({
		url: urlcore + "/api/user/getPhonePassword1",
		type: "post",
		contentType: "application/json;charset=utf-8",
		data: JSON.stringify({
			"password": password,
			"phone": phone,
			"code": code
		}),
		dataType: "json",
		success: function(data) {
			if(data.success == true) {
				if(confirm("添加成功！")) {
					//刷新
					//location.reload();
					window.location.href = "1.0.0denglu.html";
				} else {
					//跳转列表页
					window.location.href = "1.0.2zhaohuimima.html";
				}
			} else if(data.code == 'OVERTIME') {
				var thisUrl = window.location.href;
				if(thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href = "1.0.0denglu.html";
				}
			} else {
				alert(data.msg);
			}

		},
		error: function() {
			alert("error");
		}

	});
}
//登录
var youzhi="";
//收到验证码 
function selectGoodsList2() {
	var phone = $("#phone").val();
	if(!(/^1(3|4|5|7|8)\d{9}$/.test(phone))) {
		alert("手机号码有误");
		return;
	} else {
		$.ajax({
			url: urlcore + "/api/user/getPhoneCode?&phone="+phone+"&type="+1,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				console.log(data);
				if(data.success == true) {
					var da = data.data;
					youzhi=data.data;
				} else if(data.code == 'OVERTIME') {
					var thisUrl = window.location.href;
					if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
						top.window.location.href = "1.0.0denglu.html";
					}
				} else {
					alert(data.msg);
				}
// 				if(data.success == true) {
// 					
// 					youzhi=data.data;
// 				    //alert(JSON.stringify(data.data));
// 				} else {
// 					alert(data.msg);
// 				}

			},
			error: function() {
				/* Act on the event */
				alert("error");
			}
		});
	}

}


// function xiayibu(){
// 	var codess = $("#code").val();
// 	var phone=$("#phone").val();
// 	if(youzhi!=""){
//           if(youzhi!=null){
//          if(codess!=""){
//          	
//          	if(!(/^1(3|4|5|7|8)\d{9}$/.test(phone))) {
// 		alert("手机号码有误");
// 		return;
// 	} else {
// 		//alert("已有的")
// 		$.ajax({
// 			url: urlcore + "/api/user/checkOldPhone2?&phone="+phone+"&codess="+codess,
// 			type: "get",
// 			dataType: 'json',
// 			contentType: "application/json;charset=utf-8",
// 			success: function(data) {
// 				if(data.success == true) {
// 					 sessionStorage.setItem("phone",phone);
// 					 sessionStorage.setItem("codess",codess);
// 					window.location.href="1.0.0denglu.html";
// 				} else {
// 					alert(data.msg);
// 				}
// 			},
// 			error: function() {
// 				/* Act on the event */
// 				alert("error");
// 			}
// 		});
// 		}
// 		  }else{
// 		  	alert("请填写验证码");
// 		  }
//        }else{
//          if(codess!=""){
//          	if(!(/^1(3|4|5|7|8)\d{9}$/.test(phone))) {
// 					alert("手机号码有误");
// 					return;
// 	  } else {
// 		$.ajax({
// 			url: urlcore + "/api/user/checkOldPhone2?&phone="+phone+"&code="+codess,
// 			type: "get",
// 			dataType: 'json',
// 			contentType: "application/json;charset=utf-8",
// 			success: function(data) {
// 				if(data.success == true) {
// 					 sessionStorage.setItem("phone",phone);
// 					window.location.href="1.3.3zhuces.html";
// 				} else {
// 					alert(data.msg);
// 				}
// 			},
// 			error: function() {
// 				/* Act on the event */
// 				alert("error");
// 			}
// 		});
// 		}
// 		  }else{
// 		  	alert("请填写验证码");
// 		  }	
//           }
// 		  
// 	}else {
// 		alert("未发送验证码");
// 	}
// 	
// }
function xiayibu() {
	var phone = $('#phone').val().trim();
	if(phone == '') {
		alert("请输入手机号码！");
		return false;
	}
	var code = $('#code').val().trim();
	if(code == '') {
		alert("请输入验证码！");
		return false;
	}

	var password = $('#password').val().trim();
	if(password == '') {
		alert("请输入密码！");
		return false;
	}
	var repassword = $('#repassword').val().trim();
	if(repassword == '') {
		alert("请再次输入密码！");
		return false;
	}
	if(password != repassword) {
		alert("两次输入密码不一致！");
		return false;
	}
	var userName = $('#userName').val().trim();
	if(userName == '') {
		alert("请输入昵称！");
		return false;
	}
	/*if(!$("input[type='checkbox']").is(':checked')) {
		alert("请先同意《佳港商城服务协议》！");
		return false;
	}*/
	$.ajax({
		url: urlcore + "/api/user/registerUser",
		type: "post",
		contentType: "application/json;charset=utf-8",
		data: JSON.stringify({
			"userName": userName,
			"password": password,
			"repassword": repassword,
			"phone": phone,
			"code": code
		}),
		dataType: "json",
		success: function(data) {
			if(data.success == true) {
				if(confirm("添加成功！")) {
					//刷新
					//location.reload();
					window.location.href = "1.3.2zhuce_chenggong.html";
				} else {
					//跳转列表页
					window.location.href = "1.3.0zhuce.html";
				}
			} else if(data.code == 'OVERTIME') {
				var thisUrl = window.location.href;
				if(thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href = "1.0.0denglu.html";
				}
			} else {
				alert(data.msg);
			}

		},
		error: function() {
			alert("error");
		}

	});
}
